// FileLayer.cpp: implementation of the CFileLayer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FileAppLayer.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFileAppLayer::CFileAppLayer( char* pName )
	: CBaseLayer( pName )
{
	ResetHeader();
}

CFileAppLayer::~CFileAppLayer()
{

}
void CFileAppLayer::ResetHeader()
{
	m_fileHeader.fapp_totlen = 0;
	m_fileHeader.fapp_type = 0;
	m_fileHeader.fapp_msg_type = 0;
	m_fileHeader.ed = 0;
	m_fileHeader.fapp_seq_num = 0;
	memset(m_fileHeader.fapp_data,0,FAPP_DATA_SIZE);
}
BOOL CFileAppLayer::Send(unsigned char *ppayload, int nlength)
{
	
	memcpy(m_fileHeader.fapp_data,ppayload,nlength > FAPP_DATA_SIZE ? FAPP_DATA_SIZE : nlength);
	mp_UnderLayer->Send((unsigned char*)&m_fileHeader, nlength + FAPP_HEADER_SIZE,0x0830);
	return TRUE;
}

BOOL CFileAppLayer::Receive(unsigned char *ppayload )
{
	//mp_aUpperLayer[0]->Receive(ppayload);
	LPFILE_APP pFrame = (LPFILE_APP) ppayload;
	/*if(pFrame->fapp_type == 0x00)
	{
		h_file = CreateFile(
	}
*/
	return TRUE ;
}
void CFileAppLayer::setFileSize(unsigned long len)
{
	m_fileHeader.fapp_totlen = len;
}
unsigned long CFileAppLayer::GetFileSize()
{
	return m_fileHeader.fapp_totlen;
}
void CFileAppLayer::setFileType(unsigned short type)
{
	m_fileHeader.fapp_type = type;
}
unsigned short CFileAppLayer::GetFileType()
{
	return m_fileHeader.fapp_type;
}
void CFileAppLayer::setFileMsgType(unsigned char msgType)
{
	m_fileHeader.fapp_msg_type = msgType;
}
unsigned char CFileAppLayer::GetFileMsgType()
{
	return m_fileHeader.fapp_msg_type;
}
void CFileAppLayer::setFileSeqNum(unsigned long seq_num)
{
	m_fileHeader.fapp_seq_num = seq_num;
}
unsigned long CFileAppLayer::GetFileSeqNum()
{
	return m_fileHeader.fapp_seq_num;
}